﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;



namespace LDAPOfficeTool
{
    public partial class Org2Display : UserControl
    {
        int iId;
        
        LDAPServiceNS.OrganisationBean org2Display;
        Microsoft.Office.Interop.Word.Document doc2Handle;

//        TextBox txtBox2Process;
        // width of a line in organisation description
        const int ciOrgLineSize = 45;

        public Org2Display()
        {
            InitializeComponent();
            toolTip1.SetToolTip(lblOrgCn, "Link to LDAP Behördenverzeichnis");

        }

        public void EnterParameter(Microsoft.Office.Interop.Word.Document pDoc2Handle)
        {
            doc2Handle = pDoc2Handle;
        }


        public void EnterContent(int piId, LDAPServiceNS.OrganisationBean pOrg, Color pBackColor)
        {
            org2Display = pOrg;
            iId = piId;
            string s2Enter = "";

            string sCnAux = StringUtils.StringTable2OneLine(pOrg.cn, ' ') + " (" + pOrg.ou + ") ";

            lblOrgCn.Text = StringUtils.FormatWholeWords(sCnAux, ciOrgLineSize);
            s2Enter = s2Enter + StringUtils.StringTable2StringWLNeutral(pOrg.telephoneNumber, "-nix") + Environment.NewLine;
            s2Enter = s2Enter + pOrg.mail;
//            s2Enter = "BEAN: " + Environment.NewLine + "gvPhysAddr: " + pOrg.gvPhysicalAddress + Environment.NewLine + "description: 0?" + pOrg.description[0];
            txtOrg.Text = s2Enter;
            txtOrg.BackColor = pBackColor;
        }


        private void bigCopyToolStripMenuItem_Click(object sender, EventArgs e)
        {
             if (org2Display.description != null)
            {
                Microsoft.Office.Interop.Word.Selection vSelection;
                vSelection = doc2Handle.Application.Selection;
                vSelection.TypeText(StringUtils.Table2CommaCollection(org2Display.cn));
            }
            else
            {
                MessageBox.Show("No name");
            }

        }


        private void lblOrgCn_Click(object sender, EventArgs e)
        {
            string s2Open;
            s2Open = "http://ldap.gv.at/lfrz.at/ldapw/index.php?sPage=1&showDetailDn=gvOuId=" + org2Display.gvOuId + ",ou=OrgUnits,gvOuId=AT%3AB%3A103%2Cdc%3Dgv%2Cdc%3Dat&detailType=organisation";
//            MessageBox.Show("Opening: " + s2Open);
            BrowserForm org2LDAP;
            org2LDAP = new BrowserForm();
            org2LDAP.SetUri(s2Open);
            org2LDAP.Visible = true;
        }

        private void lblOrgCn_MouseEnter(object sender, EventArgs e)
        {
            this.Cursor = Cursors.Hand;
        }

        private void lblOrgCn_MouseLeave(object sender, EventArgs e)
        {
            this.Cursor = Cursors.Default;
        }

        private void descriptionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (org2Display.description != null)
            {
                Microsoft.Office.Interop.Word.Selection vSelection;
                vSelection = doc2Handle.Application.Selection;
                vSelection.TypeText(StringUtils.Table2CommaCollection(org2Display.description));
            }
            else
            {
                MessageBox.Show("No description");
            }
        }
    }
}
